<?php
$selected_cat = $data->id_dang_dich_vu;
$selected_cat_setting = array(
    'table_name' => 'dang_dichvu',
    'key_field' => 'id',
    'value_field' => 'ten_dich_vu'
);

$user_id = $this->session->userdata('admin_id');

$customer_selected_cat = $data->id_khach_hang;


if ($this->session->userdata('admin_role') == 1) {
    $customer_selected_cat_setting = array(
        'table_name' => 'khachhang',
        'key_field' => 'id',
        'value_field' => 'ten_cong_ty'
        
    );
} else {
    $customer_selected_cat_setting = array(
        'table_name' => 'khachhang',
        'key_field' => 'id',
        'value_field' => 'ten_cong_ty',
        'where' => "sale_id = $user_id"
    );
}


//set month
$months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
    "Oct", "Nov", "Dec");
ini_set("date.timezone", "Europe/Paris");

//get year
$this_day = now();
$pattern = "%Y";
$str_year = mdate($pattern, $this_day);

$start_date_long = $data->ngay_bat_dau;
$end_date_long = $data->ngay_ket_thuc;
$pattern = "%Y-%m-%d";
$str_date_start = mdate($pattern, $start_date_long);
$str_date_end = mdate($pattern, $end_date_long);
for ($i = 0; $i < 12; $i++) {
    $dropdown_data[$i + 1] = $months[$i];
}
for ($i = 0; $i < 31; $i++) {
    $day_data[$i + 1] = $i + 1;
}
for ($i = $str_year + 10; $i > $str_year - 80; $i--) {
    $year_data[$i] = $i;
}
?>

<?php echo form_open('dich_vu/sua_thong_tin/' . $data->id, array('id' => 'register')); ?>
<div id="content">
    <?php if ($this->session->flashdata('warning')): ?>
        <div class="affiche_erreur">
            <?php echo $this->session->flashdata('warning'); ?>
        </div>
    <?php endif; ?>
    <div id="title_content">Thêm mới</div>
    <?php echo form_open_multipart('dich_vu/sua_thong_tin/' . $data->id); ?>
    <table class="form_content" width="100%">
        <tr>
            <td>
                Đã thanh toán
            </td>
            <td>
                <?php
                $active = array(
                    'name' => 'tinh_trang',
                    'id' => 'tinh_trang',
                    'value' => 1,
                    'checked' => $tinh_trang_thanh_toan == 1 ? TRUE : FALSE,
                    'style' => 'margin:10px',
                );
                echo form_checkbox($active);
                ?>
            </td>
        </tr>

        <tr>
            <td>Khách hàng <span style="color:red">*</span></td>
            <td>
                <?php echo form_dropdown('khach_hang', dropdown_data($customer_selected_cat_setting), $customer_selected_cat); ?>  

            </td>
        </tr>

        <tr>
            <td>Dạng dịch vụ <span style="color:red">*</span></td>
            <td>
                <?php echo form_dropdown('dang_dich_vu', dropdown_data($selected_cat_setting), $selected_cat); ?>  
            </td>
        </tr>

        <tr>
            <td>Tên Website </td>
            <td>
                <?php if (form_error('ten_website') != "") {
                    ?> <div class="form_error"><?php echo generate_pure_text(form_error('ten_website'), '<p>', '</p>'); ?></div> <?php } ?>
                <input type="text" class="form_input" name="ten_website" size="35" maxlength="40" value="<?php echo set_value('ten_website', $data->ten_website); ?>" /></td>
        </tr>

        <tr>
            <td>Ngày bắt đầu</td>
            <td>
                D : <?php echo form_dropdown('start_date', $day_data, get_date_part($str_date_start, 'day'), 'id="day" class="short"'); ?>
                M : <?php echo form_dropdown('start_month', $dropdown_data, get_date_part($str_date_start, 'month'), 'id="month" class="short"'); ?>
                Y : <?php echo form_dropdown('start_year', $year_data, get_date_part($str_date_start, 'year'), 'id="year" class="short"'); ?>
            </td>
        </tr>

        <tr>
            <td>Ngày kết thúc</td>
            <td>
                D : <?php echo form_dropdown('end_date', $day_data, get_date_part($str_date_end, 'day'), 'id="day" class="short"'); ?>
                M : <?php echo form_dropdown('end_month', $dropdown_data, get_date_part($str_date_end, 'month'), 'id="month" class="short"'); ?>
                Y : <?php echo form_dropdown('end_year', $year_data, get_date_part($str_date_end, 'year'), 'id="year" class="short"'); ?>
            </td>
        </tr>


        <tr>
            <td colspan="2"><input type="submit" name="submit" value="Cập nhật" class="form_submit" /></td>
        </tr>
    </table>
    <?php echo form_close(); ?>
</div>